# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html

# import json
# from api.models.sp_etl.sp_advertiser import SpAdvertiser
# import datetime
# '''存储提取到的Item数据'''
# class AppstorePipeline(object):
#     def process_item(self, item, spider):

#         try:
#             advertiser_query=SpAdvertiser.select().where(SpAdvertiser.domain==item['pkgName']).get()
#         except:
#             save_state='新增'
#             advertiser_query=SpAdvertiser()
#             advertiser_query.name=item['appName']
#             advertiser_query.domain=item['pkgName']
#             advertiser_query.first_leval_type=1
#             advertiser_query.second_leval_type=4
#             advertiser_query.app_category_type=item['app_category_type']
#             advertiser_query.category=item['categoryName']
#             advertiser_query.logo_url=item['iconUrl']
#             advertiser_query.landingpage=item['storeUrl']
#             advertiser_query.developer=item['authorName']
#             advertiser_query.advertiser_pull_status=1

#             now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
#             advertiser_query.update_at=now
#             advertiser_query.create_at=now
#             advertiser_query.bk_int=5
#         else:
#             save_state='更新'
#             advertiser_query.app_category_type=item['app_category_type']
#             advertiser_query.advertiser_pull_status=1
#             now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
#             advertiser_query.update_at=now
#             advertiser_query.bk_int=5

#         if advertiser_query.save()==1:
#             print(save_state+'sp_advertiser表登记录成功,domain:'+advertiser_query.domain)
#         else:
#             print(save_state+'失败,domain:'+advertiser_query.domain)
#         return item
